<template>
	 <div>
	 	<div class="flexrow printtop">
	 		<div>
	 			<span class="save">保存</span>
	 			<button v-print="'#printMe'">打印</button>
	 		</div>
	 		<div>查询总数：[<span>{{total}}</span>]</div>
	 		<div>
	 			<input type="text" v-model="search">
	 			<label for="">结果中查找</label>
	 		</div>
	 	</div>
	 	<div>
	 		<!-- <div v-if="unfind">
	 			没有找到相关信息！
	 		</div> -->
	 		<el-table :data="tables" height="240" border highlight-current-row
    			@row-click="getdata">
			    <el-table-column prop="data_id" label="编号" width="60">
			    	<!-- <template slot-scope="scope">    
                        <span class="col-cont" v-html="showDate(scope.row.data_id)" ></span>
                    </template> -->
			    </el-table-column>
			    <el-table-column prop="title" label="标题" width="560" class='ellipsis'>
			    	<!-- <template slot-scope="scope">    
                        <span class="col-cont" v-html="showDate(scope.row.title)" ></span>
                    </template> -->
			    </el-table-column>
			    <el-table-column prop="doc_no" label="文号" width="200" class='ellipsis'>
			    	<!-- <template slot-scope="scope">    
                        <span class="col-cont" v-html="showDate(scope.row.doc_no)" ></span>
                    </template> -->
			    </el-table-column>
			     <el-table-column prop="status" label="状态" width="70">
			     	<!-- <template slot-scope="scope">    
                        <span class="col-cont" v-html="showDate(scope.row.status)" ></span>
                    </template> -->
			    </el-table-column>
			     <el-table-column prop="publish_date" label="发文日期">
			     	<!-- <template slot-scope="scope">    
                        <span class="col-cont" v-html="showDate(scope.row.publish_date)" ></span>
                    </template> -->
			    </el-table-column>
			 </el-table>				 		
	 	</div>
	 </div>
</template>
<script>
import axios from 'axios'
import storage from '../../../storage/index'

  export default {
    name: 'PrintList',
	    data() {
		    return {
		      search:'',
		      total:'',
		      tableData:[]
	        }
    	},
    	computed:{
    		tables() {
                const search = this.search
                if (search) {
                    return this.tableData.filter(dataNews => {
                        return Object.keys(dataNews).some(key => {
                            return String(dataNews[key]).toLowerCase().indexOf(search) > -1
                        })
                    })
                }
                return this.tableData
            }
    	},
    	methods:{
    		getPrintList(){
	          let id = this.$route.query.id
	          let type = this.$route.query.param_type
	          console.log(id)
	          console.log(type)
		          if(id){			          	 
			          if( type = 'year'){
			          		let url = '/law/index?category=&vocation=&special=&policy=&keyword=&publish_date_start='+id+'-01-01&publish_date_end='+id+'-12-31 23:59:59' 
							    let date = id
							    axios.get(url,{
									date
								}).then(this.getPrintListSucc)		          			
			      			    
				         	}else if(type = 'vocation'){
				         		let url = '/law/index?category=&vocation='+id+'&special=&policy=&keyword='	
				         		let vocation = id
				         		axios.get(url,{
							          vocation
							        }).then(this.getPrintListSucc)
				         	}else if(type = 'special'){
				         		let url = '/law/index?category=&vocation=&special='+id+'&policy=&keyword='	
				         		let special = id
				         		axios.get(url,{
							          special
							        }).then(this.getPrintListSucc)
				         	}else if(type = 'polity'){
				         		let url = '/law/index?category=&vocation=&special=&policy='+id+'&keyword='
				         		let policy = id
				         		axios.get(url,{
							          policy
							        }).then(this.getPrintListSucc)
				         	}else{
				         		let url = '/law/index?category='+id+'&vocation=&special=&policy=&keyword='
			      			    let category = id
			      			    axios.get(url,{
							          category
							        }).then(this.getPrintListSucc)	
				         	}				         	
				    }else{
				    	let keyword = this.$route.query.serinput
				    	var url = '/law/index?category=&vocation=&special=&policy=&keyword='+keyword
				    	axios.get(url,{
							          keyword
							        }).then(this.getPrintListSucc)
				    }
	          
    		},
    		getPrintListSucc(res){
    			res = res.data
				if (res.status==200) {	
					const data = res.msg
					this.total = data.total
					this.tableData = data.data
					if(this.total !== 0){
					    let no = data.data[0].data_id
					    storage.set('docno',no)
					}					         	
				}
    		},
    		getdata(row){
    			let id = row.data_id
    			storage.set('docno',id)
    			let NewPage = "_empty" + "?time=" + new Date().getTime() / 500;
				this.$router.push(NewPage);
				this.$router.go(-1);
    		},
    		 // showDate(val) {
       //          val = val + '';
       //          if (val.indexOf(this.search) !== -1 && this.search !== '') {
       //              return val.replace(this.search, '<font color="#409EFF">' + this.search + '</font>')
       //          } else {
       //              return val
       //          }
       //      }
    	},
    	mounted () {
	      this.getPrintList()    
	    }
  	}

</script>

<style scoped>
	.printtop{
		justify-content: space-between;
		margin-bottom: 5px;
		font-size: 14px;
	}
</style>